﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.QuestTaskBase
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System;
using System.Collections.Generic;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem
{
  public class QuestTaskBase
  {
    protected Dictionary<EventDelegateType, TriggerDelegateType> EvenTriggerDelegates;
    private DialogFlow _dialogFlow;
    private Action _onSucceededAction;
    private Action _onFailedAction;
    private Action _onCanceledAction;

    internal static void AutoGeneratedStaticCollectObjectsQuestTaskBase(
      object o,
      List<object> collectedObjects)
    {
      ((QuestTaskBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
    }

    internal static object AutoGeneratedGetMemberValueIsLogged(object o)
    {
      return (object) ((QuestTaskBase) o).IsLogged;
    }

    internal static object AutoGeneratedGetMemberValueIsActive(object o)
    {
      return (object) ((QuestTaskBase) o).IsActive;
    }

    [SaveableProperty(1)]
    public bool IsLogged { get; set; }

    [SaveableProperty(2)]
    public bool IsActive { get; private set; }

    public QuestTaskBase(
      DialogFlow dialogFlow = null,
      Action onSucceedAction = null,
      Action onFailedAction = null,
      Action onCanceledAction = null)
    {
      this.IsLogged = true;
      this.IsActive = true;
      this._onSucceededAction = onSucceedAction;
      this._onFailedAction = onFailedAction;
      this._onCanceledAction = onCanceledAction;
      this._dialogFlow = dialogFlow;
      if (this._dialogFlow == null)
        return;
      Campaign.Current.ConversationManager.AddDialogFlow(this._dialogFlow, (object) this);
    }

    public void Finish(QuestTaskBase.FinishStates finishState)
    {
      this.IsActive = false;
      if (this._dialogFlow != null)
      {
        Campaign.Current.ConversationManager.RemoveRelatedLines((object) this);
        this._dialogFlow = (DialogFlow) null;
      }
      switch (finishState)
      {
        case QuestTaskBase.FinishStates.Success:
          if (this._onSucceededAction != null)
          {
            this._onSucceededAction();
            break;
          }
          break;
        case QuestTaskBase.FinishStates.Fail:
          if (this._onFailedAction != null)
          {
            this._onFailedAction();
            break;
          }
          break;
        case QuestTaskBase.FinishStates.Cancel:
          if (this._onCanceledAction != null)
          {
            this._onCanceledAction();
            break;
          }
          break;
      }
      this._onSucceededAction = (Action) null;
      this._onFailedAction = (Action) null;
      this._onCanceledAction = (Action) null;
      CampaignEventDispatcher.Instance.RemoveListeners((object) this);
      this.OnFinished();
    }

    public void AddTaskDialogs()
    {
      if (this._dialogFlow == null)
        return;
      Campaign.Current.ConversationManager.AddDialogFlow(this._dialogFlow, (object) this);
    }

    protected virtual void OnFinished()
    {
    }

    public virtual void SetReferences()
    {
    }

    public void AddTaskDialogOnGameLoaded(DialogFlow dialogFlow)
    {
      if (!this.IsActive)
        return;
      this._dialogFlow = dialogFlow;
    }

    public void AddTaskBehaviorsOnGameLoad(
      Action onSucceededAction = null,
      Action onFailedAction = null,
      Action onCanceledAction = null)
    {
      this._onSucceededAction = onSucceededAction;
      this._onFailedAction = onFailedAction;
      this._onCanceledAction = onCanceledAction;
    }

    public enum FinishStates
    {
      Success,
      Fail,
      Cancel,
    }
  }
}
